package com.burgeon.backend.EnterpriseWeChat.rest.VipInfo;

import com.burgeon.backend.Rest.base.RESTBase;
import org.json.JSONArray;
import org.springframework.util.MultiValueMap;

import java.util.HashMap;

public class updateVipInfoById extends RESTBase {

    private String ip;
    private String account;
    private String password;

    public updateVipInfoById(String ip, String account, String password) {
        this.ip = ip;
        this.account = account;
        this.password = password;
    }

    /**
     * 发送并接收字符创
     */

    public void getData(String id, String img, String name,String birthday,String phone) throws Exception {
        String url = "http://" + ip + "/servlets/binserv/Rest";
        String str = RESULT(Data(id,img,name,birthday,phone), url);
        System.err.println(str);
        String code = new JSONArray(str).getJSONObject(0).getString("code");
        String message = new JSONArray(str).getJSONObject(0).getString("message");
        if (!"0".equals(code)) {
            throw new Exception(message);
        }
    }

    private MultiValueMap Data(String id, String img, String name, String birthday, String phone) {

        HashMap params = new HashMap();

        params.put("ID", id);
        params.put("partial_update", "true");
        params.put("table", "C_VIP");//表名
        params.put("LOGO_URL","'"+img+"'");
        params.put("VIPNAME","'"+name+"'");
        params.put("BIRTHDAY","'"+birthday+"'");
        params.put("MOBIL","'"+phone+"'");

        return DATA("ObjectModify", params, account, password);
    }

    public static void main(String[] args) throws Exception {
        updateVipInfoById g = new updateVipInfoById("39.104.240.134:55321", "nea@burgeon.com.cn", "root55321");
        g.getData("421345","http://jxfs.cloudsmicro.com:8080/img/EnterpriseWeChat/vip/app.png","薛晓秋","19810816","15299163085");
    }
}
